/*
 * sr_type.h - EnCluster Standard Representation Type Definitions
 * Clunix, glory@clunix.com, yjlee@clunix.com, 2001.6.21.
 *
 * Copyright (c) 2001-2005 by Clunix Inc. All Rights Reserved.
 */

#ifndef _SR_TYPE_H_
#define _SR_TYPE_H_

#define SR_BT_MASK	0x0f0000
#define SR_TYPE_MASK	0x0fffff
#define SR_SUBTYPE_MASK	0x00ffff

#define SR_BT(srt)		(srt & SR_BT_MASK)
#define SR_REALTYPE(srt)	(srt & ~SR_VIRTUAL)

#define SR_BUILD_TYPE(class, subtype)	((((sr_typecls_t)(class)) << 16) | (subtype))
#define SR_TYPECLASS(srt)	((sr_typecls_t)(((srt) & SR_BT_MASK) >> 16))
#define SR_SUBTYPE(srt)		((srt) & SR_SUBTYPE_MASK)
#define SR_CUSTOM		0x8000

#define SR_INVALID_TYPECLS(typecls)	((typecls) < SR_TYPECLS_NULL || (typecls) >= SR_TYPECLS_EOT)

#define SR_TYPE(srt)		((srt) & SR_TYPE_MASK)

#define SR_VIRTUAL	0x10000000
#define SR_VHMS		0x20000000
#define SR_REF		0x40000000
#define SR_HOMOSET	0x80000000
#define SR_REFHMS	0x01000000

/* SR type class */
typedef enum {
	SR_TYPECLS_NULL		= 0,
	SR_TYPECLS_INT		= 1,
	SR_TYPECLS_LL		= 2,
	SR_TYPECLS_DBL		= 3,
	SR_TYPECLS_STR		= 4,
	SR_TYPECLS_OCT		= 5,
	SR_TYPECLS_DIR		= 6,
	SR_TYPECLS_PTR		= 7,
	SR_TYPECLS_BOOL		= 8,
	SR_TYPECLS_EOT		= 9
} sr_typecls_t;

/* bits on 0xff000000 is used by sr encoder and decoder and always clear */

/* type name "null" is reserved for invalid type name */

typedef union {
	struct {
		ecm_uint32	base;
		ecm_size_t	nenum;
		const char	**enumstrs;
	} enums;
} srt_priv_t;

#define SR_TYPE_NAME_MAX	32
typedef struct _sr_type_t {
	char		name_nohomo[SR_TYPE_NAME_MAX + 8];
	char		name_homoset[SR_TYPE_NAME_MAX + 8];
	ecm_size_t	namelen;
	sr_parser_t	parser;
	srt_t		*srts_super;
	srt_t		*srts_sub;
	srt_priv_t	priv;
} sr_type_t;

#endif		/* _SR_TYPE_H_ */
